﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace LightSO.CMS.Model.EasyUI
{
    public class Column : ModelBase
    {
        /// <summary>
        /// Datagrid的栏位构造方法
        /// </summary>
        /// <param name="id">表格Id</param>
        /// <param name="title">显示名称</param>
        /// <param name="width">列宽</param>
        /// <param name="height">行高</param>
        /// <param name="hidden">是否隐藏</param>
        /// <param name="sortable">是否允许排序</param>
        /// <param name="align">排列方式</param>
        public Column(string id, string title,
            int width = 0, int height = 0,
            bool hidden = false, bool sortable = true,
            AlignEnum align = AlignEnum.Left,
            bool nowrap = false)
        {
            Id = id;
            Title = title;
            Width = GetPixel(title, width);
            Height = height;
            Hidden = hidden;
            Sortable = sortable;
            Align = align;
            NoWrap = nowrap;
        }

        private int GetPixel(string title, int width)
        {
            int defaultLen = 12, sortLen = 15, min = 50;

            if (width >= min)
                return width;

            var len = (title.Length + 1) * defaultLen + sortLen;

            if (len < min)
                return min;
            else
                return len;
        }
        /// <summary>
        /// 是否隐藏
        /// </summary>
        public bool Hidden { get; set; }

        /// <summary>
        /// 排序
        /// </summary>
        public bool Sortable { get; set; }

        /// <summary>
        /// 是否折行
        /// </summary>
        public bool NoWrap { get; set; }

        /// <summary>
        /// 对齐方式
        /// </summary>
        public AlignEnum Align { get; set; }
    }
}